<template>
	<view class="category-list">
		<!-- 加载 -->
		<view class="loading-box" v-if="!classList.length&&!noData">
			<uni-load-more status='loading'></uni-load-more>
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id='+item._id" class="item" v-for="item in classList"
				:key="item._id">
				<image lazy-load :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
		<!-- 加载 -->
		<view class="loading-box" v-if="classList.length||noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
		<view class="safe-area-inset-bottom">

		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		getWallList
	} from '@/api/api';
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	const classList = ref([])
	const noData = ref(false)
	const queryParams = {
		pageNum: 1,
		pageSize: 10,
		classid: '',
	}

	onLoad((e) => {
		queryParams.classid = e.id
		queryParams.name = e.name
		// 设置导航栏标题
		uni.setNavigationBarTitle({
			title: queryParams.name
		})
		// 获取分类列表
		getCategoryList()
	})
	// 监听页面触底事件
	onReachBottom(() => {
		// 判断是否还有数据

		if (noData.value) return
		// 页码加一
		queryParams.pageNum++
		// 获取分类列表
		getCategoryList()

	})
	// 获取分类列表
	const getCategoryList = async () => {

		// 获取分类列表
		const res = await getWallList(queryParams)
		classList.value = [...classList.value, ...res.data]
		// 判断是否还有数据
		if (res.data.length < queryParams.pageSize) {
			noData.value = true
		}
		// 存储分类列表
		uni.setStorageSync('storgClassList', classList.value)
	}
</script>

<style lang="scss" scoped>
	.category-list {
		.content {
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			gap: 10rpx;
			padding: 10upx;

			.item {
				height: 440rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
					display: block;
				}
			}
		}
	}
</style>